<?php
// 干部监督
namespace app\home\controller;
use think\Db;
class Ganbuinfo extends HomeBase {

	public function getlist() {
		$map = array();
		$guanxi = input('guanxi');		// 关系
		$order = input('order');
		if(!$order){
			$order='id DESC';
		}// 排序
		$page = input('page');			// 当前页
		$row = input('row');			// 每页显示数据

		// 查询条件
		if (!empty($guanxi)) $map['guanxi'] = $guanxi;

		// 排序
		if (empty($order)) $order = 'sort asc, create_time desc';
		
		// 分页
		if ($page = intval($page) < 1) $page = 1;
		if (!$row = intval($row)) $row = 10;
		$start = ($page-1) * $row;
		
		$list = array();
		if (!empty($map)) {
			$total = Db::name('Ganbuinfo')->where($map)->count('id');
			$list = Db::name('Ganbuinfo')->where($map)->order($order)->limit($start,$row)->field('id,sfid,name,guanxi,zhiwu,create_time')->select();
		} else {
			$total = Db::name('Ganbuinfo')->count('id');
			$list = Db::name('Ganbuinfo')->order($order)->limit($start,$row)->field('id,sfid,name,guanxi,zhiwu,create_time')->select();
		}
//		dump($list);exit;
		if (empty($list)) 
			return json(array('status'=>0,'msg'=>'暂无数据'));
		else {
			return json(array('status'=>1,'info'=>$list,'count'=>$total));
		}
	}

	public function getdetail() {
		$id = input('id');
		$id = intval($id);
		$info = Db::name('Ganbuinfo')->where('id',$id)->find();
		if (!$info)
			return json(array('status'=>0,'msg'=>'数据未找到'));
		$town = Db::name('Towns')->where('id',$info['townsid'])->field('tname')->find();
		$info['town_name'] = $town['tname'];
		return json(array('status'=>1,'info'=>$info));
	}
}